package com.zang.hash;

import java.lang.reflect.Array;
import java.util.*;

/**
 * @author ZVerify
 * @since 2022/10/12 19:26
 * @see <a href="https://leetcode.cn/problems/group-anagrams/">...</a>
 **/
public class 字母异位分组 {

    public List<List<String>> groupAnagrams(String[] strs) {

        HashMap<String, List<String>> listHashMap = new HashMap<>();

        for (String str : strs) {
            char[] chars = str.toCharArray();
            Arrays.sort(chars);

            String valueOf = String.valueOf(chars);
            if (!listHashMap.containsKey(valueOf)){
                listHashMap.put(valueOf,new ArrayList<>());
            }
            listHashMap.get(valueOf).add(str);
        }

        return new ArrayList<>(listHashMap.values());
    }
}
